home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Camelot
/
Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip
/
Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf
/
RxSlides
/
RxSlidesIn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-08
|
8KB
|
394 lines
/* :bk=0 */
/****************************************************************/
/* */
/* RxSlidesIn.c */
/* */
/* Author: Dean Bandes from Lee M. Robertson's "Dissolve" */
/* Rev : Nov 6, 1988 */
/* */
/****************************************************************/
#include "exec/types.h"
#include "exec/memory.h"
#include "graphics/gfx.h"
#include "intuition/intuition.h"
#include "storage.h"
#include <stdio.h>
#include "RxSlides.h"
#include "RxSliPic.h"
struct NewWindow NewWindow =
{
0, /* left edge */
0, /* top edge */
320, /* width */
200, /* heigth */
0,1, /* pen's */
VANILLAKEY | MOUSEBUTTONS | CLOSEWINDOW, /* IDCmpFlags */
/* flags */
RMBTRAP | WINDOWCLOSE | BACKDROP | NOCAREREFRESH | BORDERLESS | ACTIVATE,
0, /* gadget list */
0, /* check mark */
0, /* title pointer */
0, /* screen pointer */
0, /* bitmap pointer */
0,0, /* minimum sizes */
0,0, /* maximum sizes */
CUSTOMSCREEN,
};
struct NewScreen NewScreen =
{
0, /* left edge */
0, /* top edge */
320, /* width */
200, /* heigth */
5, /* depth */
0,1, /* pen's */
0, /* view modes */
CUSTOMSCREEN, /* type */
0, /* font */
(UBYTE *)"Dissolve screen", /* title */
0, /* gagets */
0, /* bitmap */
};
struct Screen *OpenScreen();
struct Window *OpenWindow();
struct ViewPort *ViewPortAddress();
struct BitMap BitMap = {0}; /* bitmap to read picture into */
struct picture pic = {0};
struct Screen *Screen = NULL;
struct ViewPort *vp = NULL;
struct Window *Window = NULL;
UBYTE svcmap[CMSIZE] = {0};
static int plane_depth_alloc = 0;
static int plane_size_alloc = 0;
/*-h- int show_pic (filename, speed, transition)
*
* char *filename name of picture file
* LONG speed speed of transition
* SHORT transition transition type
*
* Returns a status (0 = OK)
*/
int show_pic (filename, speed, transition)
char *filename;
LONG speed;
SHORT transition;
{
extern int pic_from_file ();
extern int window_for_pic ();
#ifdef DEBUG
extern LONG debug_level;
#endif
int status = 0;
status = pic_from_file ( &pic, filename );
#ifdef DEBUG
if ( debug_level > 10 )
printf (" pic_from_file returned status %d\n", status);
#endif
if ( status != STS_OK )
return (status);
status = window_for_pic (&pic);
#ifdef DEBUG
if ( debug_level > 10 )
printf (" window_for_pic returned status %d\n", status);
#endif
if ( status != STS_OK )
{
free_planes_alloc ();
return (status);
}
if ( transition < 0 )
{
#ifdef DEBUG
if ( debug_level > 10 )
printf (" transition clipped from %d to 0\n", transition);
#endif
transition = 0;
}
if ( transition > MAX_TRANSITION )
{
#ifdef DEBUG
if ( debug_level > 10 )
printf (" transition clipped from %d to %d\n",
transition,
MAX_TRANSITION);
#endif
transition = MAX_TRANSITION;
}
status = dissolve( &BitMap, Window->RPort->BitMap, speed, transition );
#ifdef DEBUG
if ( debug_level > 10 )
printf (" dissolve returned status %d\n", status);
#endif
if ( status == STS_OK )
savecolors (&svcmap[0], &pic.cmap[0]);
free_planes_alloc ();
return (STS_OK);
}
/*-h- int pic_from_file (picpt, filename)
*
* Read a "pic" struct from a file
*/
int pic_from_file (picpt, filename)
struct picture *picpt;
char *filename;
{
extern int open_pic ();
extern int rd_bmap ();
#ifdef DEBUG
extern LONG debug_level;
#endif
int i;
int psize;
int status;
if( status = open_pic( filename, picpt ))
{
#ifdef DEBUG
if ( debug_level > 10 )
printf ("open_pic status %d: %s\n", status, filename);
#endif
return( status );
}
/* setup the temp bitmap for the data */
BitMap.BytesPerRow = (picpt->bmhd.w >> 4) << 1;
BitMap.Rows = picpt->bmhd.h;
BitMap.Depth = picpt->bmhd.nPlanes;
psize = BitMap.BytesPerRow * BitMap.Rows; /* calculate the plane size */
if( psize == 0 || picpt->bmhd.nPlanes > 6 )
{
#ifdef DEBUG
if ( debug_level > 10 )
printf ("Invalid parameters: %s\n", filename);
#endif
return( STS_BAD_PSIZE );
}
/* Allocate memory for plane data */
plane_size_alloc = psize;
for( i=0; i<BitMap.Depth; i++ )
{
if( (BitMap.Planes[i] = (UBYTE *) AllocMem( psize, MEMF_CHIP)) == 0 )
{
free_planes_alloc ();
#ifdef DEBUG
if ( debug_level > 10 )
printf ("Unable to allocate bitmap memory in pic_from_file\n");
#endif
return ( STS_BAD_ALLOC );
}
else
plane_depth_alloc = i + 1;
}
/* Now read the picture into the temp bitmap */
status = rd_bmap( &BitMap, picpt );
close (picpt->fd);
if ( status != STS_OK )
{
free_planes_alloc ();
#ifdef DEBUG
if ( debug_level > 10 )
printf ("Unable to rd_bmap\n");
#endif
return (status);
}
return (STS_OK);
}
/*-h- int free_planes_alloc ()
*/
int free_planes_alloc ()
{
int i;
for( i=0; i<plane_depth_alloc; i++ )
{
FreeMem (BitMap.Planes[i], plane_size_alloc);
BitMap.Planes[i] = NULL;
}
plane_depth_alloc = 0;
plane_size_alloc = 0;
return (STS_OK);
}
/*-h- int window_for_pic (picpt)
*
* struct picture *picpt pointer to picture to display
*
* Opens a screen and window (if appropriate ones don't exist
* to display the picture in question)
*
* Returns a status (0 = OK)
*/
int window_for_pic (picpt)
struct picture *picpt;
{
/* check for existing screen and window that match */
if ( Window )
{
if (( NewWindow.Width != picpt->bmhd.w ) ||
( NewWindow.Height != picpt->bmhd.h ))
{
CloseWindow (Window);
Window = NULL;
}
}
if ( Screen )
{
if (( NewScreen.Width != picpt->bmhd.w ) ||
( NewScreen.Height != picpt->bmhd.h ) ||
( NewScreen.Depth != picpt->bmhd.nPlanes ) )
{
if ( Window )
{
CloseWindow (Window);
Window = NULL;
}
CloseScreen (Screen);
Screen = NULL;
}
}
if ( ! Screen )
{
NewScreen.Width = picpt->bmhd.w;
NewScreen.Height = picpt->bmhd.h;
NewScreen.Depth = picpt->bmhd.nPlanes;
/* set bits for display modes */
NewScreen.ViewModes = 0;
if( NewScreen.Depth == 6 && NewScreen.Width <= 320 )
NewScreen.ViewModes |= HAM;
if( NewScreen.Height > 200 )
NewScreen.ViewModes |= LACE;
if( NewScreen.Width > 320 )
NewScreen.ViewModes |= HIRES;
Screen = OpenScreen( &NewScreen);
if( Screen == 0 )
{
#ifdef DEBUG
if ( debug_level > 10 )
printf ("Unable to open screen\n");
#endif
return (STS_NO_SCREEN);
}
}
if ( ! Window )
{
NewWindow.Screen = Screen;
NewWindow.Width = picpt->bmhd.w;
NewWindow.Height = picpt->bmhd.h;
Window = OpenWindow( &NewWindow );
if( Window == 0 )
{
CloseScreen (Screen);
Screen = NULL;
#ifdef DEBUG
if ( debug_level > 10 )
printf ("Unable to open window\n");
#endif
return (STS_NO_WINDOW);
}
ShowTitle( Screen, 0L ); /* hide the screen title */
vp = ViewPortAddress( Window ); /* get the windows viewport */
SetRast( Window->RPort, 0L ); /* clear the screen */
setcolors( vp, &svcmap[0], picpt->numcolors );
}
return (STS_OK);
}
/*-h- int close_pic_window ()
*/
int close_pic_window ()
{
if ( Window )
{
CloseWindow (Window);
Window = NULL;
}
if ( Screen )
{
CloseScreen (Screen);
Screen = NULL;
}
return (STS_OK);
}
/*-h- int pic_back ()
*/
int pic_back ()
{
if ( Screen )
ScreenToBack ( Screen );
return (STS_OK);
}
/*-h- int pic_front ()
*/
int pic_front ()
{
if ( Screen )
ScreenToFront ( Screen );
return (STS_OK);
}